import java.awt.Color;
import java.util.HashMap;

/**
 * A class containing a HashMap of boolean variables allowing easy access to return and toggle attributes.
 * 
 * @author Joe Thomas
 * @version 0.2
 */
public class State
{

    // constants.
    private static final boolean DEFAULT_BOLD = false;
    private static final boolean DEFAULT_ITALIC = false;
    private static final boolean DEFAULT_UNDERLINED = false;
    private static final boolean DEFAULT_WRAPPED = false;
    
    public static final String BOLD = "b";
    public static final String ITALIC = "i";
    public static final String UNDERLINED = "u";
    public static final String WRAPPED = "w";
    
    public static final String LEFT = "left";
    public static final String RIGHT = "right";
    public static final String CENTER = "center";
    public static final String JUSTIFIED = "justified";
    
    // instance variables (fields). 
    private HashMap<String, Boolean> booleanStates;
    private String alignment; 
    private int indentation;
    private double heading;

    /**
     * A Constructor to initialise the instance variables of a new State.
     */
    public State()
    {     
        booleanStates = new HashMap<String, Boolean>();
        booleanStates.put(BOLD, DEFAULT_BOLD);
        booleanStates.put(ITALIC, DEFAULT_ITALIC);
        booleanStates.put(UNDERLINED, DEFAULT_UNDERLINED);
        booleanStates.put(WRAPPED, DEFAULT_WRAPPED);
        
        alignment = LEFT;
        
        indentation = 0;
        heading = 0.0;
        
    }
    /**
     * A method to toggle a single boolean state. That is if the state is true, it will be made to be false and visa-versa. This is a first attempt towards making sure that 
     * a state is deactivated after the visitor has left the node relating to this state for good. It takes a string which is the key of one of the attributes in the HashMap.
     * @param key The key of the attribute that needs to be toggled.  *Range: must use one of State.BOLD, State.ITALIC, State.UNDERLINED, State.WRAPPED.
     */
    public void toggleState(String key)
    {
        boolean state = booleanStates.get(key);
        if (state == true) {
            state = false;
        }
        else {
            state = true;
        }
        booleanStates.remove(key);
        booleanStates.put(key, state);
    }
    
    /**
     * A method to return the state of a single boolean state. It takes a string which is the key of one of the attributes in the HashMap.
     * @param key The key of the attribute that needs to be toggled.  *Range: must use one of State.BOLD, State.ITALIC, State.UNDERLINED, State.WRAPPED.
     */
    public boolean getState(String key)
    {
        return booleanStates.get(key);
    }
    
    /**
     * A method to set the state of indentation, passed in as an integer whose number represents the number of spaces to indent by.
     * @param indentation the number of spaces to indent by.   *Range: should be a small integer less than 20.
     */
    public void setIndentation(int indentation)
    {
        this.indentation = indentation;
    }
    
    /**
     * A method to return the current value of the indentation.
     * @return the current value of the indentation.   
     */
    public int getIndentation()
    {
        return indentation;
    }
    
    /** 
     * A method to set the heading number of a piece of text.
     * @param heading the number to set the heading to.  *Range: between 1.0 and 7.7.
     */
    public void setHeading(double heading)
    {
        if ((heading >= 1.0) && (heading <= 7.7)) {
            this.heading = heading;
        }
    }
    
    /** 
     * A method to reset the heading number to 0.0.
     */
    public void resetHeading()
    {
        heading = 0.0;
    }
    
    /** 
     * A method to get the heading number.
     * @return the heaing number.
     */
    public double getHeading()
    {
        return heading;
    }
    
    /** 
     * A method to increment the heading by a whole number.
     */
    public void incrementWhole()
    {
        heading += 1.0;
    }
    
    /** 
     * A method to increment the heading by a tenth.
     */
    public void incrementDecimal()
    {
        heading += 0.1;
    }
     
}